<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Uploadify Example Script</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    <script src="__PUBLIC__/scripts/boot.js" type="text/javascript"></script>
<script type="text/javascript" src="__PUBLIC__/file/scripts/swfobject.js"></script>
<!-- <script type="text/javascript" src="__PUBLIC__/Js/jquery.confirm.js"></script> -->
    <link href="__PUBLIC__/file/css/default.css" rel="stylesheet" type="text/css" />
	<link href="__PUBLIC__/file/css/uploadify.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript" src="__PUBLIC__/file/scripts/jquery.uploadify.v2.1.0.min.js"></script>
   <style type="text/css">
        

table.t1{
    border:1px solid #cad9ea;
    color:#666;
}
table.t1 th {
    background-image: url(th_bg1.gif);
    background-repeat:repeat-x;
    height:30px;
}
table.t1 td,table.t1 th{
    border:1px solid #cad9ea;
    padding:0 1em 0;
}
table.t1 tr.a1{
    background-color:#f5fafe;
}
    </style>
<script type="text/javascript">

 
$(document).ready(function() {
           mini.parse();
		    var pid="{$_SESSION['pid']}";
		if(pid.length<1)
          {
          	mini.alert("尚未选择项目！","提示",function(){window.CloseOwnerWindow('refresh');});
    	
         }
	$("#uploadify").uploadify({
		'uploader'       : '__PUBLIC__/file/scripts/uploadify.swf',
		'script'         : '__PUBLIC__/file/scripts/uploadify.php',
		'cancelImg'      : '__PUBLIC__/file/cancel.png',
		'folder'         : '__PUBLIC__/uploads/{$project}/{$level}',
		'queueID'        : 'fileQueue',
		'auto'           : false,
		'multi'          : true,
		'onComplete'     : function(event,queueID,fileObj,response,data)
		{
			grid.reload();
			
		}
	});
	$('a.del').click(function() {
		window.location.href=$(this).attr("href");
		});
	 
	  
});

function CloseWindow(action) {

        if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);

        else window.close();

    	} 
    	


</script>
</head>

<body>
<div class="mini-splitter" style="width:100%;height:800px;">
    <div size="70%" showCollapseButton="true" >
	<h1>项目 {$_SESSION['level']} 阶段文件管理</h1>
    <div style="width:900px;">
        <div class="mini-toolbar" style="padding:2px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                    <span>项目名称: {$_SESSION['pname']}</span>
                     &nbsp
                     <span>项目经理: {$_SESSION['managername']}</span>
                    </td>
                    <td style="white-space:nowrap;">
                       
                    </td>
                </tr>
            </table>           
        </div>
    </div>

   
 <div id='div1'>
 <div>
 	<br />
 	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="mini-button mini-button-iconTop" iconCls="icon-upload"  onclick="up()" plain="true">上传文件</a> 
<a class="mini-button mini-button-iconTop" iconCls="icon-download"  onclick="batchdown()" plain="true">项目阶段文件批量下载</a>
<p></p>
</div>


<div id="datagrid1" class="mini-datagrid" style="width:650px;height:300px;margin:20px;" 
    url="__APP__/Post/showfile1"  idField="id" allowResize="true"
    sizeList="[10,20,30,50]" pageSize="10"  
>
    <div property="columns">
        <div type="indexcolumn" >序号</div>
        <div field="orginalname" width="120" headerAlign="center" allowSort="true">文件名称</div>    
        <div field="level" width="80" headerAlign="center" allowSort="true">所属阶段</div> 
		<div name="action" width="120" headerAlign="center" align="center" renderer="onActionRenderer" cellStyle="padding:0;">操作</div>		  		
    </div>
</div>   

<!-- 
<table class="t1">
<thead>
    <tr>
        <th width="350px">文件名称</th>
		<th colspan="2" width="200px">操作</th>
		    
		
    </tr>
    </thead>
<volist name="list" id="vo">
<tr>
<td width="350px">{$vo.orginalname}&nbsp &nbsp &nbsp</td>
<td width="100px"> <a  href="__APP__/File/down/name/{$vo.orginalname}/level/{$level}">下载 </a> </td>
<td width="100px"><a  class="del" href="__PUBLIC__/php/delete.php?name={$vo.orginalname}" >删除</a></td>   
</tr>
</volist>
<table id='add' class="t1">
</table>
</table>
 -->
 <div id="win1" class="mini-window" title="文件上传" style="width:600px;height:300px"
		showMaxButton="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true"
		>
<table>
<p></p>
<tr>
<td><input width="40px" type="file" value="" name="uploadify" id="uploadify" /></td>
<td><a class="mini-button mini-button-iconTop" iconCls="icon-add"  href="javascript:jQuery('#uploadify').uploadifyUpload()" plain="true">上传队列</a></td>
<td><a class="mini-button mini-button-iconTop" iconCls="icon-remove"  href="javascript:jQuery('#uploadify').uploadifyClearQueue()" plain="true">清空队列</a></td>
</tr>
</table>
<h3>注意：文件命名规则：[项目名称]（文件内容）（来源/撰写人）（日期）</h3>
<div id="fileQueue" style="height:150px;width:480px;"></div>
</div>

</div>
</div>
    
<div showCollapseButton="true">
    	
<div id='div2'>
<table id='myTable' class="t1">
	<thead>
    <tr>
        <th>阶段需要上传文件</th>
    </tr>
    </thead>
     <tbody> 
     <volist name="filelist" id="vo">
     <tr>
     	<td>{$vo}</td>
     </tr>
     </volist>
     </tbody>
</table>
</div>
</div>     
</div>

<!--  div style="height:1px; margin-top:-1px;clear:both;overflow:hidden;"></div>-->
<script type="text/javascript">
        mini.parse();       
	
           
        var grid = mini.get("datagrid1");
   
        grid.load();
        
        var pid="{$_SESSION['pid']}";
		if(pid.length<1)
          {
          	mini.alert("尚未选择项目！","提示",function(){window.CloseOwnerWindow('refresh');});
    	
         }
         
         
         var t = mini.get("date");
         t.setValue(new Date());
		
		grid.on("rowclick", function (e) {
              //alert(e.record.mid);//弹个ID出来就好了	
			  
					showWindow();
         });
		
        var db = new mini.DataBinding();
        db.bindForm("editForm1", grid);
		
		function showWindow() {
			var win = mini.get("win1");
			win.show();
		}
		
        //对"createtime"字段，进行降级排序
        grid.sortBy("fid", "desc");
      /////////////////////////////////
		function onActionRenderer(e) {
             var grid = e.sender;
            var record = e.record;
            var uid = record._uid;
            var rowIndex = e.rowIndex;

            var s = ' <a class="Edit_Button" href="javascript:download(\'' + uid + '\')">下载</a>'
                    + ' <a class="Delete_Button" href="javascript:deletefile(\'' + uid + '\')">删除</a>';         
            return s;
        }
        function download(row_uid){
			var row = grid.getRowByUID(row_uid);
			//alert(row.orginalname);
			window.location.href="__APP__/File/down?name="+row.orginalname+"&level="+row.level;
			//alert("__APP__/File/down?name="+row.orginalname+"&level="+row.level);
		
		}
		 
		 function deletefile(row_uid){
			var row = grid.getRowByUID(row_uid);
			//alert(row.orginalname);
			window.location.href="__PUBLIC__/php/delete.php?name="+row.orginalname;
			//alert("__APP__/File/down?name="+row.orginalname+"&level="+row.level);
		
		}
		
        function search() {
            var key1=document.getElementById("key1").value;
			var key2=document.getElementById("key2").value;
			//mini.alert(state);
            grid.load({ key1: key1 , key2:key2});
        }
        $("#key1").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
        $("#key2").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
        ///////////////////////////////////////////////////////
		 function add() {

            var win = mini.get("win2");
			win.show();
        }
		

		
		function ExportExcel() {
           var pid="{$_SESSION['pid']}";
			var tablename="company_finance";
           	var filename="项目公司财务数据摘要";
			window.location.href="__APP__/File/exportexcel?tablename="+tablename+"&filename="+filename+"&pid="+pid;
       

        }
        
		 function addForm() {
			//提交表单数据
            var form = new mini.Form("#addForm1");            
            var data = form.getData(true);      //获取表单多个控件的数据
            
            $.ajax({
                url: "__APP__/Post/post_4_add",
                type: "post",
                data: { Data: data },
                success: function (text) {
                    alert("提交成功");
                    grid.reload();
                    var win = mini.get("win2");
					win.hide();
                }
            });

        }
		
		  function resetForm() {
            var form = new mini.Form("#addForm1");
            form.reset();
        }
        function batchdown(){
		
		if(grid.getData()=="")
		{	mini.alert("无文件!");
			return;
        }	
        	window.location.href="__APP__/File/downall/project/{$project}/level/{$level}";
        }
        function up(){
        
        if(checkauth()) {
					var win = mini.get("win1");
					win.show();
				}
        }
		function CloseWindow(action) {

        if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);

        else window.close();

    	} 
    	function checkauth() {
				var state = "{$_SESSION['state']}";
				if(state=="休眠"){
					mini.alert("项目休眠，需要在基本信息表中激活！");
					return false;
				}
				var uname = "{$_SESSION['nickname']}";
				var mname = "{$_SESSION['membername']}";
				var depart = "{$_SESSION['depart']}";
				var pos = mname.indexOf(uname);
				if(pos == -1 && depart != "营运" && uname != "{$_SESSION['managername']}") {
					mini.alert("无操作权限！");
					return false;
				} else
					return true;
			}
    </script>

</body>
</html>